﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChurchDiary.DAL.Contract;
using ChurchDiary.DAL.Methods;
using ChurchDiary.TableEntity;
namespace ChurchDiary.BLL
{
    public class BLL_Organization
    {
        public string GetDynamicOrganization(AllDepartMentDetails allDepartments)
        {
            string OutString = "";
            for (int i = 0; i <= allDepartments.OrganizationProfile.Count - 1; i++)
            {
                OutString+="<div class=\"form-group clearfix\">";
                OutString += "<label class=\"\">" + allDepartments.OrganizationProfile[i].OrganizationName + "<span class=\"required\">*</span></label>";
                OutString += "<div class=\"\">";
                var selid = "CHSEL" + i;
                OutString += "<select id=" + selid + " class=\"selectdepartments validate[required]\"><option value=\"\">Please select " + allDepartments.OrganizationProfile[i].OrganizationName + "</option>";
                for (int j = 0; j <= allDepartments.OrganizationPartition.Count - 1; j++)
                {
                    if (allDepartments.OrganizationProfile[i].Organiztionid == allDepartments.OrganizationPartition[j].OrganizationId)
                    {
                        OutString += "<option value=" + allDepartments.OrganizationPartition[j].PartitionId + ">" + allDepartments.OrganizationPartition[j].PartitionName + "</option>";
                    }
                }
                OutString += "";
                OutString += "</select>";
                OutString+="</div>";
                OutString+="</div>";
            }
            return OutString;
        }
        #region OrganizationPartition
        public string AddOrganizationPartion(EnitityOrganizationPartition OrganizationPartition)
        {
            IOrganization Org = new DAL_Organization();
            return Org.InsertOrganizationPartition(OrganizationPartition);
        }
        public string UpdateOrganizationPartion(EnitityOrganizationPartition OrganizationPartition)
        {
            IOrganization Org = new DAL_Organization();
            return Org.UpdateOrganizationPartition(OrganizationPartition);
        }
        public string DeleteOrganizationPartion(Guid PartitionId)
        {
            IOrganization Org = new DAL_Organization();
            return Org.DeleteOrganizationPartition(PartitionId);
        }
        public List<EnitityOrganizationPartition> GetOrganizationPartitionfordp()
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetOrganizationPartitionfordp();
        }
        public List<EnitityOrganizationPartition> GetOrganizationPartitions()
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetOrganizationPartitions();
        }
        public List<EnitityOrganizationPartition> GetOrganizationPartitions(int OrganizationId)
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetOrganizationPartitions(OrganizationId);
        }
        public EnitityOrganizationPartition GetOrganizationPartition(Guid PartitionId)
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetOrganizationPartition(PartitionId);
        }
        public string GetPartitionfilter(List<EnitityOrganizationPartition> Partition)
        {
            StringBuilder sbDepartments = new StringBuilder();
            sbDepartments.Append("<li role=\"presentation\" data-id=\"0\"><a role=\"menuitem\" tabindex=\"-1\">All</a></li>");
            foreach (EnitityOrganizationPartition lst in Partition)
            {
                sbDepartments.Append("<li role=\"presentation\" data-id=" + lst.PartitionId + "><a role=\"menuitem\" tabindex=\"-1\">" + lst.PartitionName + "</a></li>");
            }
            return sbDepartments.ToString();
        }
        public string GetOrganizationTable(List<EnitityOrganizationPartition> OrganizationPartition)
        {
            StringBuilder sbPartition = new StringBuilder();
            int i = 1;
            foreach (EnitityOrganizationPartition lst in OrganizationPartition)
            {
                sbPartition.Append("<tr class=\"even pointer\">");
                sbPartition.Append("<td class=\" \">" + lst.PartitionName + "</td>");
                sbPartition.Append("<td class=\" \">" + lst.Org.OrganizationName + "</td>");
                sbPartition.Append("<td class=\" \">" + lst.PartitionAbrivation + "</td>");
                sbPartition.Append("<td class=\" \">" + lst.Org.ParentPartition + "</td>");
                sbPartition.Append("<td class=\" \">");
                sbPartition.Append("<ul class=\"actionicons\">");
                sbPartition.Append("<li><a data-id=" + lst.PartitionId + " data-toggle=\"tooltip\" class=\"edit\" data-placement=\"bottom\" title=\"\" data-original-title=\"Edit\"><i class=\"fa fa-pencil\"></i></a></li>");
                sbPartition.Append("<li><a data-id=" + lst.PartitionId + " data-toggle=\"tooltip\" class=\"del confirmbox\" data-placement=\"bottom\" title=\"\" data-original-title=\"Delete\"><i class=\"fa fa-trash\"></i></a></li>");
                sbPartition.Append("<li><a href=\"../../Admin/OrganizationPartition/Info?PartitionId=" + lst.PartitionId + "\" class=\"view\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\" data-original-title=\"info\"><i class=\"fa fa-info-circle\"></i></a></li>");
                sbPartition.Append("</ul>");
                sbPartition.Append("</td>");
                sbPartition.Append("</tr>");
                i += 1;
            }
            return sbPartition.ToString();
        }
        public string GetOrganizationOption(List<EnitityOrganizationPartition> OrganizationPartition)
        {
            StringBuilder sbPartition = new StringBuilder();
            sbPartition.Append("<option value=\"\">Please Select</option>");
            foreach (EnitityOrganizationPartition lst in OrganizationPartition)
            {
                sbPartition.Append("<option value="+lst.PartitionId+">"+lst.PartitionName+"</option>");
            }
            return sbPartition.ToString();
        }
        #endregion
        #region organizationInfo
        public EntityOrganizationInfo GetOrganizationInfo()
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetOrganizationInfo();
        }
        public EntityUser GetUserInfo(Guid? Userid)
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetUserInfo(Userid);
        }
        public EntitySoftwareInfo GetSoftwareInfo()
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetSoftwareInfo();
        }
        #endregion
        public List<Departments> GetDepartments()
        {
            IOrganization Org = new DAL_Organization();
            return Org.GetDepartMents();
        }
        public string GetDepartmentfilter(List<Departments> Departments)
        {
            StringBuilder sbDepartments = new StringBuilder();
            sbDepartments.Append("<li role=\"presentation\" data-id=\"0\"><a role=\"menuitem\" tabindex=\"-1\">All</a></li>");
            foreach (Departments lst in Departments)
            {
                sbDepartments.Append("<li role=\"presentation\" data-id="+lst.Departmentsid+"><a role=\"menuitem\" tabindex=\"-1\">"+lst.DepartmentName+"</a></li>");
            }
            return sbDepartments.ToString();
        }
        public string GetDepartmentDropDown(List<Departments> Departments)
        {
            StringBuilder sbDepartments = new StringBuilder();
            sbDepartments.Append("<option value=\"\">Please Select</option>");
            foreach (Departments lst in Departments)
            {
                sbDepartments.Append("<option value=" + lst.Departmentsid + ">" + lst.DepartmentName + "</option>");
            }
            return sbDepartments.ToString();
        }
    }
}
